{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests_html import HTMLSession\n",
    "session = HTMLSession()\n",
    "url = 'http://www.spbeen.com/tool/request_info'\n",
    "response = session.get(url)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# HTMLResponse = requests.Response + HTML\n",
    "## HTML = BaseParser + render\n",
    "### BaseParse = xpath(Element) + find(Element)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<HTML url='http://www.spbeen.com/tool/request_info/'>\n",
      "<class 'requests_html.HTML'>\n"
     ]
    }
   ],
   "source": [
    "print(response.html)\n",
    "print(type(response.html))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Element 'a' href='/' class=('item', 'bigfont')>,\n",
       " <Element 'a' class=('item',) href='/index'>,\n",
       " <Element 'a' class=('item',) href='/index'>,\n",
       " <Element 'a' class=('header', 'item', 'bigfont') href='/'>,\n",
       " <Element 'a' class=('item',) href='/course/Python3教程'>,\n",
       " <Element 'a' class=('item',) href='/course/xpath教程/'>,\n",
       " <Element 'a' class=('item',) href='/course/Linux常用命令/'>,\n",
       " <Element 'a' class=('item',) href='/item/基于Flask的微信娱乐机器人'>,\n",
       " <Element 'a' class=('item',) href='/item/基于Python的网络爬虫'>,\n",
       " <Element 'a' class=('item',) href='/item/基于 Python 的文件备份'>,\n",
       " <Element 'a' class=('item',) href='/tool/request_info/'>,\n",
       " <Element 'a' href='/' class=('right', 'item', 'bigfont', 'mobile-tablet-item')>,\n",
       " <Element 'a' class=('section',) href='/'>]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## xpath选择器\n",
    "response.html.xpath('.//a[@href]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Element 'a' href='/' class=('item', 'bigfont')>,\n",
       " <Element 'a' class=('item',) href='/index'>,\n",
       " <Element 'a' class=('item',) href='/index'>,\n",
       " <Element 'a' class=('header', 'item', 'bigfont') href='/'>,\n",
       " <Element 'a' class=('item',) href='/course/Python3教程'>,\n",
       " <Element 'a' class=('item',) href='/course/xpath教程/'>,\n",
       " <Element 'a' class=('item',) href='/course/Linux常用命令/'>,\n",
       " <Element 'a' class=('item',) href='/item/基于Flask的微信娱乐机器人'>,\n",
       " <Element 'a' class=('item',) href='/item/基于Python的网络爬虫'>,\n",
       " <Element 'a' class=('item',) href='/item/基于 Python 的文件备份'>,\n",
       " <Element 'a' class=('item',) href='/tool/request_info/'>,\n",
       " <Element 'a' href='/' class=('right', 'item', 'bigfont', 'mobile-tablet-item')>,\n",
       " <Element 'a' class=('section',) href='/'>]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## CSS选择器\n",
    "response.html.find('a[href]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
